part of menu;
//********************* widget list menu ******************************/

/// 菜单内容
List<Map<String, dynamic>> widgetMenu = [
  {
    'label': '上移',
    'color': null,
    'icon': Icons.arrow_left,
    'onTap': forwardWidget,
  },
  {
    'label': '自动更新',
    'color': Colors.blue,
    'icon': Icons.all_inclusive,
    'onTap': autoUpdateWidget,
  },
  {
    'label': '下移',
    'color': null,
    'icon': Icons.arrow_right,
    'onTap': backwardWidget,
  },
  {
    'label': '分享',
    'icon': Icons.share,
    'color': Colors.orange,
    'onTap': shareWidget,
  },
  {
    'label': '编辑',
    'color': Colors.green,
    'icon': Icons.edit,
    'onTap': editWidget,
  },
  {
    'label': '删除',
    'color': Colors.red,
    'icon': Icons.delete,
    'onTap': deleteWidget,
  },
];

// 上移动
forwardWidget(BuildContext context, int gindex, int index) {
  Navigator.of(context).pop();
  if (index - 1 < 0) {
    showInfoBlock("无法向前移");
  } else {
    context.read<GroupListModel>().moveWidget(gindex, index, index - 1);
    showInfoBlock("移动成功");
  }
}

// 下移动
backwardWidget(BuildContext context, int gindex, int index) {
  Navigator.of(context).pop();
  if (index + 1 >= context.read<GroupListModel>().widgetLen(gindex)) {
    showInfoBlock("无法向后移");
  } else {
    context.read<GroupListModel>().moveWidget(gindex, index, index + 1);
    showInfoBlock("移动成功");
  }
}

autoUpdateWidget(BuildContext context, int gindex, int index) {
  Navigator.of(context).pop();
  showInfoBlock("暂时未开放");
}

// 分享
shareWidget(BuildContext context, int gindex, int index) {
  showInfoBlock("暂时未开放");
  Navigator.of(context).pop();
}

//编辑
editWidget(BuildContext context, int gindex, int index) {
  Navigator.of(context).pop();
  var info = context.read<GroupListModel>().getAt(gindex).widgetList[index];
  switch (info.type) {
    case ApiWidgetType.BUTTON:
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) => AddButtonForm(gindex: gindex, index: index),
      ));
      break;
    case ApiWidgetType.INFO:
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) => AddInfoForm(gindex: gindex, index: index),
      ));
      break;
    case ApiWidgetType.SLIDING:
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) => AddSlidingForm(gindex: gindex, index: index),
      ));
      break;
    case ApiWidgetType.SWITCH: // 开关
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) => AddSwitchForm(gindex: gindex, index: index),
      ));
      break;
  }
}

//删除
deleteWidget(BuildContext context, int gindex, int index) {
  Provider.of<GroupListModel>(context, listen: false).removeWidget(gindex, index);
  showSuccBlock('删除成功');
  Navigator.of(context).pop();
}

//********************* 菜单路由 ******************************/
///
showWidgetMenu(BuildContext context, int gindex, int index) async {
  for (var grid in widgetMenu) {
    grid['color'] = grid['color'] ?? modeColor(context);
  }
  try {
    Vibrate.feedback(FeedbackType.light);
  } catch (e) {}

  List<Widget> menuList = List.generate(
    widgetMenu.length,
    (i) => TIconText(
      text: widgetMenu[i]['label'],
      icon: widgetMenu[i]['icon'],
      color: widgetMenu[i]['color'],
      onTap: () => widgetMenu[i]['onTap'](context, gindex, index),
    ),
  );
  await showModalBottomSheet(
    context: context,
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(radius)),
    builder: (context) => Container(
      height: menuHeight,
      padding: const EdgeInsets.symmetric(vertical: verPadding * 2, horizontal: horPadding),
      child: Center(
          child: Column(children: [
        const TitleText("菜单"),
        Column(children: [
          const Divider(height: 40),
          Wrap(
            spacing: (MediaQuery.of(context).size.width - 3 * boxSize) / 5,
            runSpacing: verMargin,
            children: menuList,
          )
        ]),
      ])),
    ),
  );
}
